// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './assets/index.css'
import axios from 'axios'
import VueAxios from "vue-axios";

Vue.use(VueAxios, axios)

Vue.use(ElementUI)

axios.defaults.baseURL = "http://localhost:3000"
axios.defaults.withCredentials = true;

Vue.config.productionTip = false

axios.interceptors.request.use((config) => {
  let token = window.localStorage.getItem('token')
  if (token) {
    config.headers.Authorization = token
  }
  return config
}, (error) => {
  return Promise.reject(error)
})

// 时间戳转换
Vue.filter('dateFormat', function (originVal) {

  const dt = new Date(originVal)

  const y = dt.getFullYear()

  const m = (dt.getMonth() + 1 + '').padStart(2, '0')

  const d = (dt.getDate() + '').padStart(2, '0')

  const hh = (dt.getHours() + '').padStart(2, '0')

  const mm = (dt.getMinutes() + '').padStart(2, '0')

  const ss = (dt.getSeconds() + '').padStart(2, '0')

  //时间格式年月日、时分秒  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
